<!--
 * @Author: wangding
 * @Date: 2020-11-11 15:58:31
 * @LastEditTime: 2021-01-27 11:56:07
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\device\sale\add.vue
-->
<template>
    <div class="buyPage-main-box-add">
        <el-dialog
        :title="$t('export')"
        :visible="dictionaryVisible"
        width="35%"
        @close="()=>{$store.commit('setDictionaryVisible',false)}"
        :close-on-click-modal='false'
        >   
            <el-row :gutter="20">
                <el-col :span="19" :offset="2">
                    <el-form ref="form" :model="form" label-width="120px" >
                       
                        <el-form-item :label="$t('index.timeHorizon')" prop="file" :rules="[{ required: false, message: $t('index_js_notNull')}]">
                           <el-date-picker
                            v-model="form.beginTime"
                            type="date"
                            :placeholder="$t('selectDate')"
                            value-format='yyyy-MM-dd'
                            :picker-options="pickerOptions"
                            >
                            </el-date-picker>
                            -
                            <el-date-picker
                            v-model="form.endTime"
                            type="date"
                            :placeholder="$t('selectDate')"
                            value-format='yyyy-MM-dd'
                            :picker-options="pickerOptions"
                            >
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item :label="$t('download.fileName')" prop="fileName" :rules="[{ required: true, message: $t('index_js_notNull')}]"> 
                            <el-input  v-model="form.fileName" :placeholder="$t('pleaseInput')"></el-input>
                        </el-form-item>
                        <el-form-item :label="$t('introduce')" prop="remark" :rules="[{ required: false, message: $t('index_js_notNull')}]"> 
                            <el-input type="textarea"  v-model="form.remark" :placeholder="$t('pleaseInput')"></el-input>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setDictionaryVisible',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import moment from 'moment'
import baseFile from '../../../components/common/baseFileInput'
export default {
    components: {
        baseFile
    },
    props: {
        groupId:{
            type:String,
            default:''
        },
        querylist:{
            type:Object,
            default:()=>{return {}}
        }
    },
    data() {
        return {
            typeList:[{
                id:'0',
                text:"VPP"
            },{
                id:'1',
                text:"SAPN"
            }],
            form:{
                beginTime:moment().format("YYYY-MM-DD"),
                endTime:moment().format("YYYY-MM-DD"),
                fileName:"",
                remark:"",
            },
            pickerOptions:{ //禁用今天之后的时间
                disabledDate(time) {
                    return time.getTime() > Date.now()
                }
            },
        };
    },
    computed: {
        dictionaryVisible(){
            return this.$store.state.sysStore.dictionaryVisible
        }
    },
    watch: {

    },
    created() {

    },
    mounted() {

    },
    methods: {
        async deviceExportInverterData(){
            this.querylist['time'] = this.querylist.currentTime
            let res = await this.API.deviceExportInverterData(Object.assign({},this.querylist,this.form))
            if(res.code != 500){
                this.comm.showMsg(true,this.$t('download.product_tip'))
                this.$store.commit('setDictionaryVisible',false)
            }else{
                this.comm.showMsg(false)
            }
            
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.deviceExportInverterData()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
    },
};
</script>

<style  lang="less" >
.buyPage-main-box-add{
    .el-form-item__content{
        display: flex;
    }
    .icon-fontsize{
        font-size: 25px;
        margin-left: 10px;
        display: block;
        width: 25px;
        height: 33px;
    }
}
</style>
